<div class="map">
  <!-- 面包屑 -->
  <el-breadcrumb class="bread" separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    <el-breadcrumb-item>用户列表</el-breadcrumb-item>
  </el-breadcrumb>

  <!--
     el-input : 输入框组件
el-button  => append : 后面   prepend : 前面
   -->
  <el-row :gutter="20">
    <el-col :span="8">
      <el-input placeholder="请输入查询内容" v-model="input5">
        <el-button
          @click="startQuery"
          slot="append"
          icon="el-icon-search"
        ></el-button>
      </el-input>
    </el-col>
    <el-col :span="3">
      <el-button @click="showAddUserDialog">添加用户</el-button>
    </el-col>
  </el-row>

  <!--
  el-table : 表格组件
    :data="tableData" 表格数据  data 数组
  el-table-column : 表格列组件
    prop : 表格列要展示的信息
  -->
  <el-table :data="usersList" style="width: 100%">
    <el-table-column prop="username" label="姓名" width="180"></el-table-column>
    <el-table-column prop="email" label="邮箱" width="180"></el-table-column>
    <el-table-column prop="mobile" label="电话"></el-table-column>
    <el-table-column label="用户状态">
      <template slot-scope="scope">
        <el-switch
          @change="stateChanged(scope.row)"
          v-model="scope.row.mg_state"
        >
        </el-switch>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <!-- 以后自定义列 使用   <template slot-scope="scope"> , 然后在这个里main写组件-->
      <template slot-scope="scope">
        <!--
           type="primary" primary(蓝色) danger(红色) success(绿色)
           plain : 镂空
         -->
        <el-button
          type="primary"
          plain
          icon="el-icon-edit"
          @click="showEditUserDialog(scope.row)"
          size="mini"
        ></el-button>
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          @click="delUser(scope.row.id)"
          size="mini"
        ></el-button>
        <el-button type="success" plain icon="el-icon-check" size="mini"
        @click='showAssignRoleDialog(scope.row)'
          >分配角色</el-button
        >
      </template>
    </el-table-column>
  </el-table>

  <!-- 分页 -->
  <!-- total 总个数 -->
  <!-- :current-page='pagenum' 当前页 -->
  <!-- :page-size='2' 每页的条数  -->
  <el-pagination
    @current-change="pageChanged"
    background
    layout="prev, pager, next"
    :current-page="pagenum"
    :page-size="2"
    :total="total"
  >
  </el-pagination>

  <!--
     第一个对话框 : 添加用户 对话框
     el-dialog : 对话框组件
     visible.sync="dialogFormVisible" 负责显示和隐藏对话框
     label-width="180px" 添加给form, 会通过继承,下面子组件都可以使用
   -->
  <el-dialog @close='dialogClosed'  title="添加用户" :visible.sync="dialogAddUserVisible">
    <el-form ref='addUserForm' :model="addUserForm" label-width="100px" :rules="rules">
      <el-form-item label="用户名" prop="username">
        <el-input v-model="addUserForm.username" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="addUserForm.password" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop='email'>
        <el-input v-model="addUserForm.email" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="手机" prop='mobile'>
        <el-input v-model="addUserForm.mobile" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="dialogAddUserVisible = false">取 消</el-button>
      <el-button type="primary" @click="addUser">确 定</el-button>
    </div>
  </el-dialog>

  <!--
    第二个对话框 : 编辑用户对话框
   -->
  <el-dialog title="编辑用户" :visible.sync="dialogEditUserVisible">
    <el-form :model="editUserForm" label-width="100px">
      <el-form-item label="用户名">
        <el-tag type="info">{{ editUserForm.username }}</el-tag>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="editUserForm.email"></el-input>
      </el-form-item>
      <el-form-item label="手机">
        <el-input v-model="editUserForm.mobile"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="dialogEditUserVisible = false">取 消</el-button>
      <el-button type="primary" @click="editUser">确 定</el-button>
    </div>
  </el-dialog>

  <!-- 第三个对话框 : 分配角色 对话框 -->
  <el-dialog title="分配角色" :visible.sync="dialogAssignRoleVisible">
    <el-form :model="assignRoleForm" label-width="100px">
      <el-form-item label="用户名" >
        <el-tag>{{ assignRoleForm.username }}</el-tag>
      </el-form-item>
      <el-form-item label="角色列表" >
        <el-select v-model="assignRoleForm.rid" placeholder="请选择角色">
          <!--
            label : 是展示给别人 看的
            value : 我们收集的是value的值
           -->
          <el-option v-for='item in roleList' :key='item.id' :label="item.roleName" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogAssignRoleVisible = false">取 消</el-button>
      <el-button type="primary" @click="assignRole">确 定</el-button>
    </div>
  </el-dialog>
</div>
